package com.ruoyi.business.controller;

import java.time.LocalDateTime;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.Waterchillerhis;
import com.ruoyi.business.service.IWaterchillerhisService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 水冷机历史数据Controller
 * 
 * @author DL
 * @date 2025-07-07
 */
@RestController
@RequestMapping("/waterchillerhis")
public class WaterchillerhisController extends BaseController
{
    @Autowired
    private IWaterchillerhisService waterchillerhisService;

    /**
     * 查询水冷机历史数据列表
     */
    //@RequiresPermissions("business:waterchillerhis:list")
    @GetMapping("/list")
    public TableDataInfo list(Waterchillerhis waterchillerhis)
    {
        startPage();
        List<Waterchillerhis> list = waterchillerhisService.selectWaterchillerhisList(waterchillerhis);
        return getDataTable(list);
    }

    /**
     * 导出水冷机历史数据列表
     */
    //@RequiresPermissions("business:waterchillerhis:export")
    @Log(title = "水冷机历史数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Waterchillerhis waterchillerhis)
    {
        List<Waterchillerhis> list = waterchillerhisService.selectWaterchillerhisList(waterchillerhis);
        ExcelUtil<Waterchillerhis> util = new ExcelUtil<Waterchillerhis>(Waterchillerhis.class);
        util.exportExcel(response, list, "水冷机历史数据数据");
    }

    /**
     * 获取水冷机历史数据详细信息
     */
    //@RequiresPermissions("business:waterchillerhis:query")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(waterchillerhisService.selectWaterchillerhisByID(ID));
    }

    /**
     * 新增水冷机历史数据
     */
    //@RequiresPermissions("business:waterchillerhis:add")
    @Log(title = "水冷机历史数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Waterchillerhis waterchillerhis)
    {
        return toAjax(waterchillerhisService.insertWaterchillerhis(waterchillerhis));
    }

    /**
     * 修改水冷机历史数据
     */
    //@RequiresPermissions("business:waterchillerhis:edit")
    @Log(title = "水冷机历史数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Waterchillerhis waterchillerhis)
    {
        return toAjax(waterchillerhisService.updateWaterchillerhis(waterchillerhis));
    }

    /**
     * 删除水冷机历史数据
     */
    //@RequiresPermissions("business:waterchillerhis:remove")
    @Log(title = "水冷机历史数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(waterchillerhisService.deleteWaterchillerhisByIDs(IDs));
    }

    /**
     * 水冷机数据折线图
     */
    @GetMapping("/realtime-data")
    public Map<String, Object> getRealtimeData() {
        // 获取最近15分钟的数据
        LocalDateTime endTime = LocalDateTime.now();
        LocalDateTime startTime = endTime.minusMinutes(15);

        // 从数据库查询数据
        return waterchillerhisService.getWaterDataBetween(startTime, endTime);
    }
}
